package com.ljh.account.controller;

import com.github.pagehelper.PageInfo;
import com.ljh.account.dao.BankAccountBinding;
import com.ljh.account.service.BankAccountBindingService;
import com.ljh.account.utils.Response;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/protected")
public class BankAccountBindingController {
    @Autowired
    private BankAccountBindingService bankAccountBindingService;

//    绑定银行卡
    @PostMapping("/bind")
    public Response bind(@RequestBody BankAccountBinding bankAccountBinding){

        bankAccountBindingService.addBinding(bankAccountBinding);
        return Response.success("银行卡绑定成功！");
    }
    @GetMapping("/bind")
    public Response bind(HttpServletRequest request, @RequestParam int page, @RequestParam int size){
        Object userId = request.getAttribute("userId");
        PageInfo allBindings = bankAccountBindingService.getAllBindings((Long) userId, page, size);
        return Response.success(allBindings);
    }
}
